#include <iostream>

using namespace std;

/*
    【题目195】编写-一个程序，设计一个产品类Product，其中包含产品名称、单价、剩余数量等数据成员，以及若干成员函数。
*/

class Product
{
private:
    string name;
    double price;
    int count;

public:
    Product(string n, double p, int c)
    {
        name = n;
        price = p;
        count = c;
    }

    void show()
    {
        cout << "name:" << name << endl;
        cout << "price:" << price << endl;
        cout << "count:" << count << endl;
    }

    ~Product()
    {
        cout << "析构函数" << endl;
    }

    void buy(int n)
    {
        if (count >= n)
        {
            count -= n;
        }
        else
        {
            cout << "库存不足" << endl;
        }
    }

    void showCount()
    {
        cout << "剩余数量:" << count << endl;
    }
};

int main()
{
    Product p1("apple", 5.5, 100);
    p1.show();
    p1.buy(10);
    p1.showCount();
    p1.buy(100);
    p1.showCount();
    return 0;
}